package com.longge;

import java.util.PriorityQueue;

public class LastStoneWeight {

    public int lastStoneWeight(int[] stones) {

        PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a);

        for (int stone : stones) {
            pq.offer(stone);
        }
        while (pq.size() > 1) {
            Integer a = pq.poll();
            Integer b = pq.poll();
            if (a > b) {
                pq.offer(a - b);
            }

        }
        return pq.isEmpty() ? 0 : pq.poll();


    }
}
